<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="cfn" uri="http://francetelecom.com/cfn"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/fn"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@page import="org.springframework.validation.Errors"%>

<%-- Prints, if necessary, the list of the error message linked to the field denoted
      by the passed path. Parameters are :
    - path : the path for the form element for which errors should be displayed.
 --%>

<%-- Displaying the form field error message --%>
<spring:bind path="${param.path}*">

  <c:if test="${status.error}">

    <c:set var="errorCodeIndex" value="0"/>
    <c:if test="${not empty param.errorCodeIndex}">
      <c:set var="errorCodeIndex" value="${param.errorCodeIndex}"/>
    </c:if>

    <span class="error">
      <c:forEach items="${status.errors.fieldErrors}" var="error">

        <c:if test="${fn:startsWith(error.field, param.path)}">

          <%-- Getting the right error message --%>
          <c:set var="errorMsg" value=""/>

          <c:forEach items="${error.codes}" var="code">
            <c:if test="${empty errorMsg}">
              <spring:theme var="errorMsg" code="${code}"
                arguments="${error.arguments}" text=""/>
            </c:if>
          </c:forEach>

          <c:if test="${not empty errorMsg}">
            ${errorMsg}<br/>
          </c:if>
        </c:if>
      </c:forEach>

    </span>
  </c:if>
</spring:bind>